import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [

    {
      path: '/test', name: 'about', component: () => import('../views/Test.vue')
    },
    {
      path: '/button', name: 'button', component: () => import('../views/Element-Plus-Button.vue')
    },
    {
      path: '/icons', name: 'icons', component: () => import('../views/Icons.vue')
    },
    {
      path: '/input', name: 'input', component: () => import('../views/Element-Plus-input.vue')
    },
    {
      path: '/select', name: 'select', component: () => import('../views/El-select.vue')
    },
    {
      path: '/radio', name: 'radio', component: () => import('../views/El-Radio.vue')
    },
    {
      path: '/checkbox', name: 'checkbox', component: () => import('../views/El-Checkbox.vue')
    },
    {
      path: '/image', name: 'image', component: () => import('../views/El-Image.vue')
    },
    {
      path: '/carousel', name: 'carousel', component: () => import('../views/El-Carousel.vue')
    },
    {
      path: '/date_picker', name: 'date_picker', component: () => import('../views/El-Date-Picker.vue')
    },
    {
      path: '/table', name: 'table', component: () => import('../views/El_table.vue')
    },
    {
      path: '/father', name: 'father', component: () => import('../views/Father.vue'),
      children: [
        {path: 'son1', name: 'son1', component: () => import('../views/Son1.vue')},
        {path: 'son2', name: 'son2', component: () => import('../views/Son2.vue')}
      ]
    },
    {path:'/manager', name:'manager', component:()=>import('../views/Manager.vue'),
      children:[
        {path:'/manager/data', name:'data',meta:{title:'数据管理'},component:()=>import('../views/Data.vue'),
        },
        {
          path:'/manager/home', name:'home',meta:{title:'首页'},component:()=>import('../views/Home.vue'),
        },
        {
          path: '/manager/admin',
          name: 'admin',
          meta: {title: '管理员管理'},
          component: () => import('../views/Admin.vue')
        }

      ]
    },
    {path:'/404', name:'找不到', component:()=>import('../views/404.vue')},
      // 匹配所有路由
      {path:'/:pathMatch(.*)*', redirect:'/404'}
  ]
})
  router.beforeEach((to,from,next) => {
    document.title=to.meta.title;
    next()  //必须调用
  })


export default router
